/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: user
 * Date: 2023-06-18
 * Time: 13:40
 */
public class MyQueue {
    public class ListNode {


        public int val;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
        public ListNode head;
        public ListNode last;


        private int Usedsize;

    public void offer(int val){
         ListNode node = new ListNode(val);
         if (head ==null){
             head = node;
             last = node;
         }else {
             last.next = node;
             last = last.next;
         }
         Usedsize++;
    }
    public int getUsedsize(){
        return Usedsize;
    }

    public int poll() {
        if (head ==null){
            return -1;
        }
        int val = -1;
        if (head.next==null){
            val = head.val;
            head =null;
            last=null;
            return val;
        }else {
            val =head.val;
            head=head.next;
            Usedsize--;
            return val;
        }
    }

    public int peek(){
        if (head==null){
            return -1;
        }
        return head.val;
    }

}
